Giving this a |nowiki option to wrap the returned path in <nowiki>s for non-linked standalone use.
Added File::getFullURL() function for cleaner calls; using full path to ensure consistency here.
=== New features in 1.12 ===
* Add a warning for non-descriptive filenames at Special:Upload
+* Add {{filepath:}} parser function to get full path to an uploaded file,
+ complementing {{fullurl:}} for pages.
+
=== Bug fixes in 1.12 ===
$parser->setDefaultSort( $text );
return '';
}
+
+ public static function filepath( $parser, $name='', $option='' ) {
+ $file = wfFindFile( $name );
+ if( $file ) {
+ $url = $file->getFullUrl();
+ if( $option == 'nowiki' ) {
+ return "<nowiki>$url</nowiki>";
+ }
+ return $url;
+ } else {
+ return '';
+ }
+ }
}
} elseif($this->mMode=="file") {
$type="Edit file";
$image = wfLocalFile( $this->mTitle );
- $img_url = $image->getURL();
- if(strpos($img_url,"://")) {
- $url = $img_url;
- } else {
- $url = $wgServer . $img_url;
- }
+ $url = $image->getFullURL();
$extension=substr($name, $pos);
}
$special=$wgLang->getNsText(NS_SPECIAL);
$this->setFunctionHook( 'anchorencode', array( 'CoreParserFunctions', 'anchorencode' ), SFH_NO_HASH );
$this->setFunctionHook( 'special', array( 'CoreParserFunctions', 'special' ) );
$this->setFunctionHook( 'defaultsort', array( 'CoreParserFunctions', 'defaultsort' ), SFH_NO_HASH );
+ $this->setFunctionHook( 'filepath', array( 'CoreParserFunctions', 'filepath' ), SFH_NO_HASH );
if ( $wgAllowDisplayTitle ) {
$this->setFunctionHook( 'displaytitle', array( 'CoreParserFunctions', 'displaytitle' ), SFH_NO_HASH );
}
return $this->url;
}
+
+ /**
+ * Return a fully-qualified URL to the file.
+ * Upload URL paths _may or may not_ be fully qualified, so
+ * we check. Local paths are assumed to belong on $wgServer.
+ * @return string
+ */
+ public function getFullUrl() {
+ $url = $this->getUrl();
+ if( substr( $url, 0, 1 ) == '/' ) {
+ global $wgServer;
+ return $wgServer . $url;
+ }
+ return $url;
+ }
function getViewURL() {
if( $this->mustRender()) {
'padright' => array( 0, 'PADRIGHT' ),
'special' => array( 0, 'special', ),
'defaultsort' => array( 1, 'DEFAULTSORT:', 'DEFAULTSORTKEY:', 'DEFAULTCATEGORYSORT:' ),
+ 'filepath' => array( 0, 'FILEPATH:' ),
);
/**